const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
    data: {
        userInfo: '',
        kfconcatnums: '',
        myDataCountdata: "",
        counts:{}
    },
    onLoad: function(options) {

    },
    onShow: function() {
        this.info()
        this.orderCount()
    },
    //获取用户信息
    info() {
        Controller.info().then(res => {
            if (res.data.baseData) {
                this.setData({
                    userInfo: res.data.baseData
                })
            }
        })
    },
    orderCount(){
       Controller.orderCountList({}).then(res=>{
              this.setData({
                  counts:res.data.baseData||{}
              })
       })
    },
    goPage(e) {
        let url = e.currentTarget.dataset.url
        wx.navigateTo({
            url
        })
    },
    goPersonInfo(e) {
        wx.navigateTo({
            url: '/pages/Me/personInfo',
        })
    },
    info() {
        Controller.info().then(res => {
            if (res.data.baseData) {
                this.setData({
                    userInfo: res.data.baseData
                })
            }
        })
    },
    myDataCount() {
        Controller.myDataCount().then(res => {
            if (res.data.baseData) {
                this.setData({
                    myDataCountdata: res.data.baseData,
                })
            }
        })
    },
    kfconcat() {
        Controller.appinfo({ key: "key-phone" }).then(res => {
            if (res.data.baseData) {
                this.setData({
                    kfconcatnums: res.data.baseData.content
                })
            }
        })
    },
    contact(e){
     console.log('contact',e)
    },
    golink(e) {
        if (!wx.getStorageSync('logintoken')) {
            app.ToLogin(true)
            return
        }
        var url = e.currentTarget.dataset.url;
        wx.navigateTo({
            url: url
        })
    },
    concat(e) {

        wx.showActionSheet({
            itemList: [e.currentTarget.dataset.tel, '呼叫'],
            success: function(res) {
                if (res.tapIndex == 1) {
                    wx.makePhoneCall({
                        phoneNumber: e.currentTarget.dataset.tel,
                    })
                }
            }
        })
    },
    onShareAppMessage: function(e) {
        let title = '';
        let imageUrl = '';
        let path = app.getCurrentPageUrlWithArgs()
        let obj = {
            title,
            imageUrl,
            path,
            success: function(res) {},
            fail(err) {}
        }
        return obj
    },
    onShareTimeline: function(res) {
        let title = '';
        let imageUrl = '';
        let path = app.getCurrentPageUrlWithArgs()
        let obj = {
            title,
            imageUrl,
            path,
            success: function(res) {},
            fail(err) {}
        }
        return obj
    },
})